package com.last.security;


/**
 * <p>title: com.wfx.filter</p>
 * author zhuximing
 * description:
 */
// extends BasicAuthenticationFilter
public class MyBasicAuthenticationFilter  {
    //
    //public MyBasicAuthenticationFilter(AuthenticationManager authenticationManager) {
    //    super(authenticationManager);
    //}

    //重写过滤器核心方法

    //@Override
    //protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
    //   // 1:获取jwt令牌
    //    String token = request.getHeader("token");
    //    if (token == null) {
    //        response(response,new Result(false,"请指定token"));
    //        return;
    //    }
    //
    //  try {
    //      // 2:解析jwt令牌
    //      //String publicKeyPath = ResourceUtils.getFile("classpath:ras_public").getPath();
    //      //PublicKey publicKey = RsaUtils.getPublicKey(publicKeyPath);
    //      //
    //      //// 从令牌中解析数据
    //      //WxbCustomer wxbCustomer = (WxbCustomer) JwtUtils.getInfoFromToken(token, publicKey, WxbCustomer.class);
    //      //
    //      //// 获取权限,角色
    //      ///// String joinStr = userInfo.getRoleAndAuth();
    //      //
    //      //// List<GrantedAuthority> grantedAuthorities = AuthorityUtils.commaSeparatedStringToAuthorityList(joinStr);
    //      ////放入springsecurity的上下文
    //      //UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = new UsernamePasswordAuthenticationToken(wxbCustomer, null, null);
    //      //
    //      //SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken);
    //      //
    //      //// 放行
    //      chain.doFilter(request, response) ;
    //
    //  }catch (Exception e){
    //      e.printStackTrace();
    //      //  令牌解析失败
    //      response(response,new Result(false,"请输入正确的令牌"));
    //  }
    //}
    //
    //
    //private void  response(HttpServletResponse response, Result res){
    //   try {
    //       response.setContentType("application/json;charset=utf-8");
    //       response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    //       PrintWriter out = response.getWriter();
    //
    //       out.write(new ObjectMapper().writeValueAsString(res));
    //       out.flush();
    //       out.close();
    //   }catch (Exception e){
    //
    //   }
    //
    //}
}